'''
Created on 2016年9月5日

@author: fxd
'''
from _ast import Nonlocal
def test(state):
    s=state
    def inner(label):
        nonlocal state
        print(label,state)
        state+=1
    return inner
 
F=test(10)
F('apple')
F('banana')
F('pair')
G=test(40)
F('people')
G('human')

state=20
def test1(start):
    global state
    state=start
    def inner(label):
        global state
        print(label,state)
        state+=1
    return inner
F=test1(20)
F('apple')
F('banana')
F('pair')
G=test1(40)
F('people')
G('human')     

X='Spam'
def func():
    X='NI'
    def nested():
        nonlocal X
        print(X) 
    nested() 
func();
print(X)